[Go] Add strictResponseDecoding option to Go-server generator. Fixes issue #21446#21456
Closed
Chimdi511 wants to merge 2 commits intoOpenAPITools:masterfrom
Closed
[Go] Add strictResponseDecoding option to Go-server generator. Fixes issue #21446#21456Chimdi511 wants to merge 2 commits intoOpenAPITools:masterfrom
Chimdi511 wants to merge 2 commits intoOpenAPITools:masterfrom
Conversation
…default, and also allow a permissive option
Member
|
please merge the latest master to your branch and regenerate the samples again let me know if you need any help |
wing328
reviewed
Jul 3, 2025
| d.DisallowUnknownFields() | ||
| {{/isAdditionalPropertiesTrue}} | ||
| {{/strictResponseDecoding}} | ||
| if err := d.Decode(&{{paramName}}Param); err != nil {{^required}}&& !errors.Is(err, io.EOF) {{/required}}{ |
Member
There was a problem hiding this comment.
thanks for the pr
before introducing another option, did you try setting disallowAdditionalPropertiesIfNotPresent to false (or true which should be the default)?
Member
|
closing as there's no update |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new generator property,
strictResponseDecoding, to the go-server generator. When enabled (the new default), every JSON decoder in generated handlers will callDisallowUnknownFields(), causing the server to reject any incoming payloads that contain fields not defined in the spec. Users can disable strict mode and allow extra fields by passing--additional-properties strictResponseDecoding=false. Fixes issue #21446.Changes
Codegen configuration
File:
GoServerCodegen.javaWhat’s changed:
STRICT_RESPONSE_DECODINGCLI option (default:true).strictResponseDecodingboolean inadditionalPropertiesfor use in templates.Template guard
File:
server.mustacheWhat’s changed:
decoder.DisallowUnknownFields()in a{{#strictResponseDecoding}}…{{/strictResponseDecoding}}block.Documentation
File: Go-server README (
modules/openapi-generator/README.md)What’s changed:
--additional-properties=strictResponseDecoding={true|false}flag, its default behavior, and usage example.Impact
Backward compatibility:
Client generation:
Usage Example
Checklist
GoServerCodegen.javaserver.mustachetemplate@antihax @grokify @kemokemo @jirikuncar @ph4r5h4d @lwj5
PR checklist
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)